package com.example.privacy.dialog;

import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
import com.example.privacy.R;

public class ItemDialog extends Dialog {
    private Button yes;
    private Button no;
    private TextView local1;
    private TextView local2;
    private String l1, l2;
    private String yesStr,noStr;
    private onNoOnclickListener noclickListener;
    private onYesOnclickListener onYesOnclickListener;

    public ItemDialog(Context context){
        super(context);
    }

    @Override
    public void onCreate(Bundle bundle){
        super.onCreate(bundle);
        setContentView(R.layout.item_dialog);
        setCanceledOnTouchOutside(false);
        local1 = (TextView) findViewById(R.id.dialogNowLocal);
        local2 = (TextView) findViewById(R.id.dialogNextLocal);
        yes = (Button) findViewById(R.id.yes);
        no = (Button) findViewById(R.id.no);
        initEvent();
        initData(l1, l2);
    }

    public void initEvent(){
        yes.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if(onYesOnclickListener != null){
                    onYesOnclickListener.YesClick();
                }
            }
        });
        no.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if(noclickListener != null ){
                    noclickListener.NoClick();
                }
            }
        });
    }

    public void initData(String nowLocal, String nextLocal){
        if(nowLocal != null){
            local1.setText(nowLocal);
        }
        if(nextLocal != null){
            local2.setText(nextLocal);
        }
    }

    public void setLocal1and2(String l1, String l2){
        this.l1 = l1;
        this.l2 = l2;
    }
    public interface onYesOnclickListener{
        public void YesClick();
    }
    public interface onNoOnclickListener{
        public void NoClick();
    }

    public void setOnYesOnclickListener(String str, onYesOnclickListener Ylistener){
        if(str != null){
            yesStr = str;
        }
        this.onYesOnclickListener = Ylistener;
    }

    public void setNoclickListener(String str, onNoOnclickListener Nlistener){
        if(str != null){
            noStr = str;
        }
        this.noclickListener = Nlistener;
    }
}
